package com.apchernykh.rozhlasapp;

import com.apchernykh.ceskyrozhlas.basic.R;
import com.apchernykh.rozhlasapp.ui.RozhlasAppBaseFragmentActivity;
import com.apchernykh.types.ApplicationModel;

import android.app.AlertDialog;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;


public class RozhlasPreferencesActivity extends PreferenceActivity {
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle iSavedInstanceState) {
		super.onCreate(iSavedInstanceState);
		// Load the preferences from an XML resource
		addPreferencesFromResource(R.xml.preferences);
	}

	@SuppressWarnings("deprecation")
	@Override
	public boolean onPreferenceTreeClick(
			final PreferenceScreen iPreferenceScreen, final Preference iPreference) {

		if (iPreference.getKey().equals("allow_alarm_catch")
				&& iPreference.getSharedPreferences().getBoolean(
						"allow_alarm_catch", false)) {
			final AlertDialog.Builder aBuilder = new AlertDialog.Builder(this);
//			MainApplication.instance(getApplicationContext()).mAlarmHelper
//					.createAlarmStubMP3();
			aBuilder.setTitle(R.string.upozorneni);
			aBuilder.setPositiveButton("OK", null);
			aBuilder.setMessage(R.string.upozorneni_budik);
			aBuilder.create().show();
		}

		else if (iPreference.getKey().equals("allow_recording_button")
				&& iPreference.getSharedPreferences().getBoolean(
						"allow_recording_button", false)) {
			final AlertDialog.Builder aBuilder = new AlertDialog.Builder(this);
			aBuilder.setTitle(R.string.upozorneni);
			aBuilder.setPositiveButton("OK", null);
			aBuilder.setMessage(R.string.upozorneni_nahravka);
			aBuilder.create().show();
		}
		return super.onPreferenceTreeClick(iPreferenceScreen, iPreference);
	}

	@Override
	protected void onResume() {
		RozhlasAppBaseFragmentActivity.mApplicationModel.mBackgroundPlaybackService.onReceivedFocus();
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		ApplicationModel.preferencesChanged();
		RozhlasAppBaseFragmentActivity.mApplicationModel.mBackgroundPlaybackService.onLostFocus();
		super.onPause();
	}
}
